home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / varie / number.rdm < prev    next >
Text File  |  1997-01-18  |  6KB  |  216 lines

  1. Short:    Convert Arabic numerals to many languages
  2. Author:   Scott Deerwester, ported by Stefan Haubenthal
  3. Uploader: hauben00@marvin.informatik.uni-dortmund.de (Stefan Haubenthal)
  4. Type:     misc/math
  5.  
  6.     ::::    Description    ::::
  7.  
  8. This version of number was inspired from the standard
  9. version in /usr/games, but with a big difference:  It
  10. knows how to count in a *lot* of languages, and can
  11. be taught almost anything that it doesn't already know.
  12. The information on how to count in a given language
  13. is given in a grammar, written in a meta-language described
  14. a little later.  Grammars exist, as of this moment, for:
  15.  
  16. Cantonese        French        Japanese    Spanish
  17. Chinese (Mandarin)    Gaellic (Irish)    Malinke        Susu
  18. English            German        Pular        Vietnamese
  19. Esperanto        Italian        Romanian
  20.  
  21. It takes about twenty minutes with a native speaker to
  22. write a grammar, once you understand how to do so.  Instructions
  23. on how to write a grammar are included at the end of this
  24. file.  It is also highly recommended that you study some
  25. of the existing grammars before attempting your own.
  26.  
  27.     ::::    Installation    ::::
  28.  
  29. - Make a directory for this package, and cd to it.
  30. - Run 'sh' on the file that you put this shell archive
  31.   in in order to extract all of the files in it.
  32. - Edit the Makefile to indicate where you want the
  33.   executable, and the grammar files to be kept.
  34.  
  35. ** Important: THIS MUST BE DONE BEFORE YOU COMPILE NUMBER!
  36.  
  37. - Type 'make install'
  38.  
  39.     ::::    Adding languages    ::::
  40.  
  41. ** Note:  If all you want to do is use number, you can skip the
  42.       rest of this file.
  43.  
  44. The grammar files used by number contain rules that
  45. number uses to translate numbers into words.  The
  46. rules are generally of the form:
  47.  
  48. n    rules
  49.  
  50. where 'n' is the "base" number, separated by a single tab from
  51. the rule per se.  The rules must be in ascending order of
  52. base number.  The basic algorithm that number uses to
  53. translate a number to words is to find the rule with
  54. the largest base that is smaller than the number, and
  55. evaluate the rule for that base, given the number.  For
  56. example, one might have the rule:
  57.  
  58. 5    "five"
  59.  
  60. which, if the number being translated were 5, would cause
  61. the rule "five" to be evaluated.  In this case, the rule
  62. is a simple string, which would be printed.  Rules may
  63. contain:
  64.  
  65. - Strings, delimited by double quotes, which are simply printed.
  66. - Spaces, which are printed as well.
  67. - A number, which causes the number to be spelled.
  68. - The following special characters, with the meanings:
  69.   /  Spell the number divided by the base.
  70.   %  Spell the number modulus the base.
  71. - A conditional, described below.
  72. - A single character macro.
  73. - A comma, which functions as a no-op.
  74.  
  75. In addition, grammars contain macro definitions, and may
  76. contain lines of comments, which have a '#' in the first
  77. column.  Rules may be continued across multiple lines by
  78. terminating the line with a '\'.  The next line must
  79. begin with a tab character.
  80.  
  81. Conditionals have the following syntax:
  82.  
  83. (L C R    rule)
  84.  
  85. with a tab separating the 'R' from the rule.  L and R
  86. are either numbers, or one of the characters:
  87.  
  88. /    Number divided by base.
  89. %    Number modulus base.
  90. B    Base.
  91. #    Number.
  92. L    Recursion level.
  93.  
  94. C is one of '<', '>', '=' or '~', meaning less than,
  95. greater than, equal to, or not equal to, respectively.
  96. The following (common) rule, taken from the grammar
  97. for Esperanto, expresses the fact that for units
  98. of 10, the number divided by 10 is only added before
  99. the word for 10 if is greater than 1:
  100.  
  101. 10    (/ > 1    /)"dek" %
  102.  
  103. Thus, if 23 were being evaluated, the conditional would
  104. check to see if 23 / 10 is greater than 1, and, since it
  105. is, evaluate the rule '/' causing 2 to be spelled.  Given
  106. the following grammar:
  107.  
  108. 0    "zero"
  109. 1    "unu"
  110. 2    "du"
  111. 3    "tri"
  112. 4    "kvar"
  113. 5    "kvin"
  114. 6    "ses"
  115. 7    "sep"
  116. 8    "ok"
  117. 9    "na[bre]u"
  118. 10    (/ > 1    /)"dek" %
  119. 100    (/ > 1    /) "cent" %
  120.  
  121. and the number 23, the following would happen:
  122.  
  123. - Select rule for base 10, number 23, since 10 is the largest
  124.   base that is smaller than 23.
  125.   - Evaluate the conditional '(/ > 1    /)'.
  126.     - Evaluate / -> 23 / 10 -> 2.
  127.     - Evaluate 2 > 1 -> TRUE.
  128.     - Evaluate / -> 23 / 10 -> 2.
  129.       - Evaluate rule for base 2, number 2.
  130.     - Print "du".
  131.   - Print "dek".
  132.   - Print " ".
  133.   - Evaluate % -> 23 % 10 -> 3.
  134.     - Evaluate rule for base 3, number 3.
  135.       - Print "tri"
  136.  
  137. The net result is that "dudek tri" is printed.
  138.  
  139.     ::::    Macros    ::::
  140.  
  141. A macro is defined by the following syntax:
  142.  
  143. /    c    rule
  144.  
  145. where c is any letter except L and B.  (Other characters
  146. are allowed as well, but don't bump into special characters...)
  147. In the grammar given above, for Esperanto, we could have
  148. used a macro to simplify the rules for 10 and 100, thus:
  149.  
  150. /    d    (/ > 1    /)
  151. 10    d"dek" %
  152. 100    d "cent" %
  153.  
  154. The following is about the most complicated piece of
  155. code in a grammar, and illustrates most of the features
  156. of the grammar metalanguage.
  157.  
  158. 10    (/ > 1    /) "m'u~'"(/ = 1    "[`]")"'o~'i" a
  159. /    a    (/ > 1    (% = 1    "m[^']ot")(% > 1    c))(/ = 1    c)
  160. /    c    (% = 5    "l[)]am")(% ~ 5    %)
  161. 100    ...
  162.  
  163. It expresses the following:
  164.  
  165. - For any number greater than or equal to 10, but less
  166.   than 100, first spell the number divided by ten, if
  167.   the quotient is greater than one.
  168. - Print the string "m'u~'".
  169. - If the quotient is 1, then print the string "[`]".
  170. - Print the string "'o~'i".
  171. - Expanding the macro 'a', if the quotient is greater
  172.   than 1:
  173.   - If the number modulus the base is 1, print the string "m[^']ot".
  174.   - If the modulus is greater than 1, expanding macro c:
  175.     - If the modulus is 5, print "l[)]am".
  176.     - If the modulus is not 5, evaluate the modulus.
  177. - If the quotient is 1, expanding macro c:
  178.   - If the modulus is 5, print "l[)]am".
  179.   - If the modulus is not 5, evaluate the modulus.
  180.  
  181. The essence of all of this is that if, in Vietnamese, something
  182. comes before the word "m'u~'[`]'o~'i", which means 10, it
  183. loses its tone ("[`]").  Further, the word for 1 (normally
  184. "m[^.]ot" changes its tone in some circumstances, and the
  185. word for 5 ("n[)]am") changes its initial letter to an "l"
  186. in still other situations.  Whew.
  187.  
  188. Macros can be handy for making very short rules.  For example,
  189. in German, 30, 40, etc. are spelled by adding the letters "zig"
  190. to the word for the number divided by 10.  Thus, with the
  191. following macro:
  192.  
  193. /    z    "zig"
  194.  
  195. the rule for 30 can be reduced from:
  196.  
  197. 30    "dreizig"
  198.  
  199. to:
  200.  
  201. 30    3z
  202.  
  203.     ::::    Conclusion    ::::
  204.  
  205. If you write any grammars, I'd greatly appreciate having
  206. them.  My permanent net address is:
  207.  
  208.     scott@cerberus.uchicago.edu
  209.  
  210. USnail address:
  211.  
  212.     Scott Deerwester
  213.     1100 E. 57th, GLS
  214.     University of Chicago
  215.     Chicago, Illinois 60637
  216.